<?php

// $Id$


require_once($WSC->get_site_inc_dir().'modules/tangra_cms/_sys/tcms_admin_page_w_grid_ua.class.php');
require_once($WSC->get_site_inc_dir().'modules/tangra_cms/grids/attachments/attachments_grid_ctrl.class.php');


class Attachments_WP extends TCMS_Admin_Page_W_Grid_UA {
	public function create_view($name = 'default') {
		$ret = new TCMS_Admin_Page_View($this, $name, 'modules/tangra_cms/pages/_attachment/');

		return $ret;
	}


	protected function create_grid_ctrl() {
		$tvm = $this->get_tvm();

		if (!$tvm->is_page_var_registered('attachments', 'filename')) {
			$tvm->register_page_var('attachments', 'filename');
			$tvm->register_page_var('attachments', 'note');
		}
		$this->process_filter($tvm);

		$ret = new Attachments_Grid_Ctrl('attachments', $tvm, Tangra_Parameter_Method::GET);

		return $ret;
	}


	private function process_filter($vm) {
		$context = $this->get__context();
		if ($context->exists_in_get('filename')) {
			$filename = $context->get_from_get('filename');
			$vm->set_page_var('attachments', 'filename', $filename);
		}
		$filename = $vm->get_page_var('attachments', 'filename');
		$this->export('filename', $filename);


		if ($context->exists_in_get('note')) {
			$note = $context->get_from_get('note');
			$vm->set_page_var('attachments', 'note', $note);
		}
		$note = $vm->get_page_var('attachments', 'note');
		$this->export('note', $note);
	}
}